< previous page page_124 next page >

Page 124
Listing 5.7. continued
    blnOK = False
    '
    ' check high/low field
    If Val(txtHighLow) < intLow Or Val(txtHighLow) > intHigh Then
        MsgBox strHighLowMsg
        blnOK = False
        txtHighLow.SetFocus
    End If
    '
    ' check upper field
    If Len(txtUpper) < intMinLen Or Len(txtUpper) > intMaxLen Then
        MsgBox strMinMaxMsg
        blnOK = False
        txtUpper.SetFocus
    End If
    '
    ' set if all passed
    If blnOK = True Then
        Unload Me
    End If
    '
End Sub
In Listing 5.7, you added variables for the minimum and maximum length of the entry field, a new message variable, and a flag variable to show that all validation steps passed. Notice that you changed the structure of the validation steps from a simple If_Then_Else to a series of If_Then routines. If the validation does not pass, a flag is set to make sure the form does not unload.
Save and run the form to test the validation rule. You see that now both form-level validation rules must be met before the form unloads.
Note.gif
The txtUpper field has both field-level and form-level validation rules applied to it. The field-level routine executes when data is entered into the field. The form-level validation routine executes when this data record is saved. It is perfectly acceptable, and sometimes recommended, to have both field-level and form-level validation for the same control.

 
< previous page page_124 next page >

If you like this book, buy it!